package com.bac.utils;

import java.util.List;

import com.bac.bacplatform.MyWalletActivity;
import com.bac.bacplatform.R;
import com.bac.javabeans.Wallet;
import com.bac.javabeans.WealthAccountJournalInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MyWalletListAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater minflater;
	private List<WealthAccountJournalInfo> lw;
	private double max;
	private ViewHolder holder;
	public MyWalletListAdapter(Context context,List<WealthAccountJournalInfo> lw,double max){
		this.context = context;
		this.minflater = LayoutInflater.from(context);
		this.lw = lw;
		this.max = max;
	}

	@Override
	public Object getItem(int position) {
		return lw.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public int getCount() {
		return lw.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = minflater.inflate(R.layout.my_item, null);
			holder = new ViewHolder();
			holder.year_text = (TextView) convertView.findViewById(R.id.tv_02);
			holder.inconme_text = (TextView) convertView.findViewById(R.id.tv_03);
			holder.front_layout = (RelativeLayout) convertView.findViewById(R.id.front_layout);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.year_text.setText(lw.get(position).getCurrentDate());
		holder.inconme_text.setText(lw.get(position).getCurrentProfit().doubleValue()+"");
		
		double width = (lw.get(position).getCurrentProfit().doubleValue()/max)*MyWalletActivity.viewWlenth;
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams((int)width,280);
		holder.front_layout.setLayoutParams(param);
		return convertView;
	}
	class ViewHolder{
		RelativeLayout front_layout;
		TextView year_text;
		TextView inconme_text;
	}
}
